window.onload = function () {
    // 轮播图效果
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: true,
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },
        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        }
    })
}
$(function () {

    // 调用首页数据接口
    $.get(baseUrl+'/system/indexData',{},function (res) {
        if(res.code != 0){
            layer.msg(res.msg);
            return false;
        }
        console.log(res);

        // 替换topAd图片
        $('.banner .main>a').remove();
        res.data.topAd.forEach(function(item,index){
            let html = `<a href="${item.href}"><img src="${item.imgSrc}"></a>`;
            $('.banner .main').append(html);
        })

        // 替换mobile,imgSrc图片
        let html2 = `<img src="${res.data.mobile.imgSrc}"></a>`
        $('.MIX').html(html2);

        // 接口数据渲染到手机商品
        $('.shouji .phone').remove();
        res.data.mobile.goods.forEach(function (item2,index2) {
            let html3 = `<a href="goods.html?goodsId=${item2.id}" class="phone">
                <img src="${item2.goodsImg}">
                <p>${item2.goodsName}</p>
                <p>${item2.goodsBody}</p>
                <p><span>${item2.shopPrice}元</span><span>${item2.marketPrice}元</span></p>
            </a>`;
            $('.shouji .main').append(html3);
        })
    },'json')
})
